<template>
  <!-- 告警提示 -->
  <DFModal ref="dfModal" class="basicModal" @register="modalRegister" @on-ok="okModalFn">
    <template #default>
      <div class="errorTip">
        <p v-for="(item, key) in props.alarmList" :key="key">
          [{{ getAlarmTypeNameFn(item) }}] {{ item.alarmName }}
        </p>
      </div>
    </template>
  </DFModal>
</template>

<script lang="ts" setup>
  import { DFModal, useModal } from '@/components/DFModal';

  import { useMixins } from '@/hooks/useMixins';

  interface Props {
    alarmList?: any;
    alarmTypeList?: any;
  }

  const emit = defineEmits(['distributionFn', 'getParameterUnitByMaterialVersionFn', 'register']);

  const props = withDefaults(defineProps<Props>(), {
    alarmList: () => [],
    alarmTypeList: () => [],
  });

  const [modalRegister, { openModal, closeModal, setSubLoading }] = useModal({});

  const { t } = useMixins();

  async function openModalFn() {
    openModal(null, t('productionCenter.table.alarm'));
  }

  function closeModalFn() {
    closeModal();
  }

  const getAlarmTypeNameFn = (item) => {
    return props.alarmTypeList.find((i) => i.value === item.alarmTypeCode)?.label || '-';
  };

  const plcClick = inject('plcClick', (_obj) => {});

  const okModalFn = async () => {
    // closeModal();

    plcClick({ funId: 'alarmReset', value: 1 });

    nextTick(() => {
      setSubLoading(false);
    });
  };

  defineExpose({
    openModalFn,
    closeModalFn,
  });
</script>
